package pCloud.server;

import pCloud.PCloudFactory;
import pCloud.config.PCloudConfig;
import pCloud.service.AccessControlHandle;
import pCloud.service.DataServerProxyServerProtHandle;
import pCloud.service.ProtocolHandle;
import pCloud.transport.Communicator;
import pCloud.transport.EndPointTransportHandle;

public class DataServerAcceptor extends Acceptor {

	DatabaseHandle databaseHandler = null;
	AccessControlHandle accessControlHandler = null;
	
	public DataServerAcceptor(int port, Communicator comm,
			DatabaseHandle databaseHandler, AccessControlHandle ach) throws Exception {
		super(port, comm);
		this.databaseHandler = databaseHandler;
		this.accessControlHandler = ach;
	}

	@Override
	public EndPointTransportHandle getServerTransportHandle(int port)
			throws Exception {
		EndPointTransportHandle ep = PCloudFactory
				.getEndPointTransportHandle(PCloudConfig
						.getString(PCloudConfig.PCLOUD_TRANSPORT_SERVER));
		ep.initalize("", port);
		return ep;
	}

	@Override
	public ProtocolHandle getNewProtocolHandle() throws Exception {
		DataServerProxyServerProtHandle ph = (DataServerProxyServerProtHandle) PCloudFactory
				.getNewProtocolHandleInstance(PCloudConfig
						.getString(PCloudConfig.PCLOUD_DATA_SERVER_PROT));

		ph.initializeDatabaseHandler(this.databaseHandler);
		ph.initializeAccessControlHandler(this.accessControlHandler);
		return ph;
	}

}
